package com.dongnao.jack.spring.parse;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

@Deprecated
public class BaseBeanDefinitionParser implements BeanDefinitionParser {

    @Override
    public BeanDefinition parse(Element element, ParserContext parserContext) {

        BeanDefinitionParser parse;
        String sb;
        Map<String, BaseBeanDefinitionParseInterface> parseMap = BeanDefinitionParserBuilderMap.getInstance();
        String id = element.getAttribute("id");
        if (StringUtils.isNotBlank(id)) {
            sb = id;
        } else {
            sb = element.getAttribute("name");
        }

        if (StringUtils.isBlank(sb)) {
            return null;
        }

        for (String key : parseMap.keySet()) {
            BaseBeanDefinitionParseInterface parseInterface = parseMap.get(key);
            if (parseInterface.support(key)) return parseInterface.parse(element, parserContext);

        }

        return null;
    }

}
